class Solution:
  def validateStackSequences(self, pushed: list, popped: list) -> bool:
    stack, i = [], 0
    for num in pushed:
      stack.append(num)
      while stack and stack[-1] == popped[i]:
        stack.pop()
        i = i + 1
    return len(stack) == 0
      

def stringToIntegerList(input):
  import json
  return json.loads(input)


def main():
  import sys
  import io

  def readlines():
    for line in io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8'):
      yield line.strip('\n')

  lines = readlines()
  while True:
    try:
      line = next(lines)
      pushed = stringToIntegerList(line)
      line = next(lines)
      popped = stringToIntegerList(line)

      ret = Solution().validateStackSequences(pushed, popped)

      out = (ret)
      print(out)
    except StopIteration:
      break


'''
STATUS: LEARNT
TRIES:  N/A
TIME:   76 MS
MEMORY: 13.5 MB
'''
if __name__ == '__main__':
  main()
